import sys, os, os.path

#print "the number of args is %d" % (len(sys.argv)-1)

if (len(sys.argv)==1 or (not os.path.isdir(sys.argv[1]))):
    print "Please input a real path!"
    sys.exit(1)

PMPDIR = sys.argv[1]
if PMPDIR[-1] == "\\" :
    PMPDIR = PMPDIR[:-1]

fnlist = os.listdir(PMPDIR)

#print fnlist 

PMPFL = []
LOGFL = []

for filename in fnlist:
    if filename[-4:].lower() == ".pmp":
        PMPFL.append(filename)
        continue
    if filename[-4:].lower() == ".log":
        LOGFL.append(filename)
        continue

#print "PMP files are"
#print PMPFL
#print "LOG files are"
#print LOGFL


for logfile in LOGFL:
    os.remove(PMPDIR + "\\" + logfile)

for pmpfile in PMPFL:
    p=pmpfile.find(".x264")
    if p >= 0:
        os.rename(PMPDIR + "\\" + pmpfile,
                  PMPDIR + "\\" + pmpfile[:p]+pmpfile[p+5:])
